package com.cn.wanxi.thread.threadtwo;

public class Productor extends Thread {

    //生产者的run方法，一直向仓库添加元素
    public void run() {
//方法重写 继承关系，名字和参数必须一致
        while (true) {
            synchronized (WareHouse.object) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(WareHouse.count + "Productor");
                if (WareHouse.count >= 10) {
                    System.out.println("仓库已经满了");
                    try {
                        WareHouse.object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    WareHouse.object.notifyAll();
                    WareHouse.count++;
                }
            }
//            synchronized (WareHouse.object) {
//                if (WareHouse.count == 0) {
//                    break;
//                } else {
//                    if (!WareHouse.isNull) {
//                        System.out.println("生产者生产产品");
//                        WareHouse.count++;
//                        WareHouse.isNull = true;
////                        WareHouse.object.notifyAll();
//                    } else {
////                        try {
////                            WareHouse.object.wait();
////                        } catch (InterruptedException e) {
////                            e.printStackTrace();
////                        }
//
//                    }
//                    System.out.println(WareHouse.count + "-" + WareHouse.isNull.toString());
//                }
//            }
        }
    }
}